*-------------------------------------------------------------------------------
clear
set more off
*-------------------------------------------------------------------------------
*-------------------------------------------------------------------------------
*globals
*INSERT YOUR PATH HERE 
global path ""

global wd"$path/VOX/vox_dta"
global wdmac "$path/VOX/vox_dta"
global target "$path/VOX/vox_dta/workingfiles"
global targetmac "$path/VOX/vox_dta/workingfiles"

*ssc install isvar
*ssc install fre

*-------------------------------------------------------------------------------
*ALL VARIABLES TO LOWERCASE TO PREPARE FOR APPEND
*-------------------------------------------------------------------------------
cd $wdmac

forvalues w=58(1) 85    {
use $wdmac/vox`w'.dta
rename *, lower
cd $targetmac
save vox`w'.dta, replace
}

*there is no wave 86, so:
forvalues w=87(1) 113    {
use $wdmac/vox`w'.dta
rename *, lower
cd $targetmac
save vox`w'.dta, replace
}
*there is no wave 114 either, so:

forvalues w=115(1) 121    {
use $wdmac/vox`w'.dta
rename *, lower
cd $targetmac
save vox`w'.dta, replace
}




global values a91n a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg

*-------------------------------------------------------------------------------
*RECODING EACH WAVE INDIVIDUALLY
*-------------------------------------------------------------------------------
*WAVES 58/59

forvalues w=58(1)59{
use $targetmac/vox`w'.dta, clear

*recode p02
recode p02 1=3 2=2 3=4 4=1 5=5 6=20 7=21 8=7 9=22 10=9 11=11 12=8 13=12 14=23 15=10 16=15 17=17 18=19, gen(p02_new)

*recode s41 
recode s41 (8=6)
label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 15 "mehrere Parteien gleichzeitig" 17 "keine Partei" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP", replace
label values p02_new p02_new
fre p02_new
 
if `w' ==58 { 
	*a91n not existing
	gen a91n=.
}

*a91mg not existing
gen a91mg=a91m

*e911 e912  not existing
gen e911 = .
gen e912 = .

*s14a1n not existing
gen s14a1n = .

gen voxnr=`w'


keep bildung s15 s41 s18 s12 s11 s61 s60 p04 p08 p01 s60 p02_new a01 a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz voxnr stdatum


if `w'==58 {
gen refdate = mdy(03,10,1996)
format refdate %dM_d,_CY

}

if `w'==59 {
gen refdate = mdy(06,09,1996)
format refdate %dM_d,_CY
*recode s60
recode s60 (1=.) (2=1) (3=2) (4=3) (5=4)

*recode s61
recode s61 (1=.) (2=1) (3=2) (4=3) (6=5) (7=6)

*recode s41
recode s41 (7=6)

*recode bildung

recode bildung (1=3) (2=1) (3=2) (4=3)

}


gen gewteil=1

*date of interview
gen date  = string(stdatum,"%06.0f")
replace date = substr(date,3,2) + substr(date,1,2)+ "19" +substr(date,5,2)

if `w'==59 {
replace date = substr(date,3,2) + substr(date,1,2)+ "1996"


}

gen intdate = daily(date, "MDY")

format intdate %dM_d,_CY

rename p02_new p02
label var p02 "Affinität zur Partei"

if `w'==58 { 

*a91a: offen vs. verschliessen

recode a91a (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91c: starke Armee vs. keine Armee

recode a91c (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91e: grosse Einkommensunterschiede vs. keine Einkommentsunterschiede
recode a91e (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91f: Vollbeschäftigung stark vs. schwach betont

recode a91f (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91g: starke vs. schwache Beteiligung der Bürgerinnen und Bürger an Regierungsentscheiden

recode a91g (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91h: Chancengleichheit Frauen / Männer

recode a91h (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91i: Chancengleichheit Ausländerinnen

recode a91i (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91j: Umweltschutz/Wohlstand

recode a91j (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91k: Staatseingriffe/Wettbewerb

recode a91k (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91l: Bund/Kanton mehr Macht

recode a91l (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91mg: CH Offenheit/Traditionsschutz

recode a91mg (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


} 


if `w'==59 { 

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

foreach var in s14a2 s14a3 s14a4 s14a5 s14a6  {

recode `var' (1=.) (2=1) (3=2) (4=3)

}

} 

save $targetmac/vox`w'_clean.dta, replace


}

*-------------------------------------------------------------------------------

*Wave 60

use $targetmac/vox60.dta, clear

*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=20 6=5 7=22 8=10 9=7 10=8 11=21 12=2 13=1 15=24 16=22 17=14 18=15 19=16 20=17 21=18 23=19, gen(p02_new)

*recode s41 
recode s41 (8=6)

rename alter s12 

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 12 "CSP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB", replace
label values p02_new p02_new
fre p02_new
 
 
*a91mg not existing
gen a91mg=a91m

*e911 e912  not existing
gen e911 = .
gen e912 = .

*s14a1n not existing
gen s14a1n = .

gen voxnr=60

recode p04 (14=13)
*recode s60
recode s60 (1=.) (2=1) (3=2) (4=3) (5=4)

*recode s61
recode s61 (1=.) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6)

keep bildung s15 s41 s18 s11 s12 s61 s60 p04 p08 p01 p02_new a01 a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz voxnr stdatum

gen refdate = mdy(12,01,1996)
format refdate %dM_d,_CY


gen date  = string(stdatum,"%06.0f")

replace date = substr(date,3,2) + substr(date,1,2)+ "19" +substr(date,5,2)
gen intdate = daily(date, "MDY")
format intdate %dM_d,_CY

rename p02_new p02
label var p02 "Affinität zur Partei"

gen gewteil=1

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

foreach var in s14a2 s14a3 s14a4 s14a5 s14a6 {

recode `var' (1=.) (2=1) (3=2) (4=3)

}

save $targetmac/vox60_clean.dta, replace
*-------------------------------------------------------------------------------

*Wave 61

use $targetmac/vox61.dta, clear

*recode s41 
recode s41 (6/7=6)


*unify p02's value labels for all waves (coded -1 and 17 to "no answer"):
recode p02 1=19 2=12 3=4 4=9 5=3 6=20 7=5 8=22 9=10 10=7 11=8 12=21 13=2 14=1 15=23 16=24 17=19 18=14 19=15 20=16 21=17 22=18, gen(p02_new)
*recode s60
recode s60 (-1=.) (2=1) (3=2) (4=3) (5=4)
label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 12 "CSP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP", replace
label values p02_new p02_new
fre p02_new
 
 
*a91mg not existing
recode a91m (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

gen a91mg=a91m

*e911 e912  not existing
gen e911 = .
gen e912 = .

*s14a1n not existing
gen s14a1n = .

*recode s61
recode s61 (1=.) (2=1) (3=2) (4=3) (5=4) (6=5) (7=6)

gen voxnr =61

keep bildung s15 s41 s18 s11 s12 s61 s60 p08 p04 p01 p02_new a01 a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz voxnr stdatum

gen refdate = mdy(06,08,1997)
format refdate %dM_d,_CY


gen date  = string(stdatum,"%06.0f")

replace date = substr(date,3,2) + substr(date,1,2)+ "19" +substr(date,5,2)
gen intdate = daily(date, "MDY")
format intdate %dM_d,_CY


rename p02_new p02
label var p02 "Affinität zur Partei"

gen gewteil=1

*a91a: Wertpraef: Ruhe und Ordnung

recode a91a (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

*a91c: starke Armee vs. keine Armee
recode a91c (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91e: grosse Einkommensunterschiede vs. keine Einkommentsunterschiede
recode a91e (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91f: Vollbeschäftigung stark vs. schwach betont
recode a91f (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

*a91g: starke vs. schwache Beteiligung der Bürgerinnen und Bürger an Regierungsentscheiden

recode a91g (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91h: Chancengleichheit Frauen / Männer

recode a91h (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

*a91i: Chancengleichheit Ausländerinnen

recode a91i (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)


*a91j: Umweltschutz/Wohlstand

recode a91j (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)


*a91k: Staatseingriffe/Wettbewerb

recode a91k (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)


*a91l: Bund/Kanton mehr Macht

recode a91l (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91n: CH öffnet/verschliesst

recode a91n (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)


foreach var in s14a2 s14a3 s14a4 s14a5 s14a6 {

recode `var' (1=.) (2=1) (3=2) (4=3)
label define `var' 1 "ja" 2 "nein" 3 "Antowortverweigerung", replace
label values `var' `var'

}

save $targetmac/vox61_clean.dta, replace

*-------------------------------------------------------------------------------

*WAVES 62 -  82

forvalues w=62(1)82 {


use $targetmac/vox`w'.dta, clear


*recode s41 
recode s41 (6/7=6)

if inlist(`w', 64, 65, 66 ) {

*could not find out what value lables these should be, ok to drop?
drop if p02==16

}

if inlist(`w', 64, 66, 67, 68, 69, 70, 71, 72, 73, 76, 78){

*no date variable
gen stdatum=.
}

if inrange(`w', 62,68) { 

 gen gewteil =1

}

if inlist(`w',70,81){
 gen gewteil =1

}

if inrange(`w', 62,71) { 
*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=20 6=5 7=22 8=10 9=7 10=8 11=21 12=2 13=1 14=23 15=24 16=25 17=14 18=15 19=16 20=17 21=18 22=19, gen(p02_new)
}


if inrange(`w', 72,82) { 
*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=11 6=5 7=22 8=10 9=7 10=8 11=21 12=2 13=1 14=23 15=24 16=25 17=14 18=15 19=16 20=17 21=18 22=19, gen(p02_new)
}

*recode s41 
recode s41 (6/7=6)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 13 "BDP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG", replace
label values p02_new p02_new
fre p02_new

if inrange(`w', 62,76) { 
	*a91mg not existing
	gen a91mg=a91m

}


if inrange(`w', 62,77) { 
	*e911 e912  not existing
	gen e911 = .
	gen e912 = .

}

if inrange(`w', 62,79) {
	*s14a1n not existing
	gen s14a1n = .

}

if inrange(`w', 76, 82) {

	rename plz qtplz

}

gen voxnr = `w'

keep bildung s15 s41 s18 s11 s12 s61 s60 p08 p04 p01 a01 p02_new a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz voxnr gewteil stdatum

if `w'==62 {
gen refdate = mdy(09,28,1997)
format refdate %dM_d,_CY

*recode s60
recode s60 (1=.) (2=1) (3=2) (4=3) (5=4)

*recode s61
recode s61 (1=.) (2=1) (3=2) (4=3) (5=4) (6=5)

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

foreach var in s14a2 s14a3 s14a4 s14a5 s14a6 {

recode `var' (1=.) (2=1) (3=2) (4=3)

}

}

}

if `w'==63 {
gen refdate = mdy(06,07,1998)
format refdate %dM_d,_CY

*a91a: Wertpraef: Ruhe und Ordnung

recode a91a (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91c: starke Armee vs. keine Armee
recode a91c (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91e: grosse Einkommensunterschiede vs. keine Einkommentsunterschiede
recode a91e (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91f: Vollbeschäftigung stark vs. schwach betont
recode a91f (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91g: starke vs. schwache Beteiligung der Bürgerinnen und Bürger an Regierungsentscheiden

recode a91g (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91h: Chancengleichheit Frauen / Männer

recode a91h (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91i: Chancengleichheit Ausländerinnen

recode a91i (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91j: Umweltschutz/Wohlstand

recode a91j (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)


*a91k: Staatseingriffe/Wettbewerb

recode a91k (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91l: Bund/Kanton mehr Macht

recode a91l (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91n: CH öffnet/verschliesst

recode a91n (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)


replace a91mg=a91m
*a91mg: CH offen/traditionen schützen

recode a91mg (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*s12: age

recode s12 1=21 2=28 3=35 4=42 5=49 6=56 7=63 8=70 9=77 10=82


}

if `w'==64 {
gen refdate = mdy(09,27,1998)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==65 {
gen refdate = mdy(11,29,1998)
format refdate %dM_d,_CY

*interview date variable contains errors:
replace stdatum= 30198 if stdatum== 30180 
replace stdatum= 290198 if stdatum== 290180 
replace stdatum= 300198 if stdatum== 300180 
replace stdatum= 280198 if stdatum== 280180 

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}
 
}

if `w'==66 {
gen refdate = mdy(02,07,1999)
format refdate %dM_d,_CY

*a91a: Wertpraef: Ruhe und Ordnung

recode a91a (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91c: starke Armee vs. keine Armee
recode a91c (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91e: grosse Einkommensunterschiede vs. keine Einkommentsunterschiede
recode a91e (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91f: Vollbeschäftigung stark vs. schwach betont
recode a91f (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91g: starke vs. schwache Beteiligung der Bürgerinnen und Bürger an Regierungsentscheiden

recode a91g (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91h: Chancengleichheit Frauen / Männer

recode a91h (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)

*a91i: Chancengleichheit Ausländerinnen

recode a91i (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91j: Umweltschutz/Wohlstand

recode a91j (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)


*a91k: Staatseingriffe/Wettbewerb

recode a91k (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91l: Bund/Kanton mehr Macht

recode a91l (1=1) (2=2) (3=3) (4=7) (5=4) (6=5) (7=6)


*a91n: CH öffnet/verschliesst

recode a91n  (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

*a91mg: CH offen/traditionen schützen

recode a91mg (1=6) (2=5) (3=4) (4=7) (5=3) (6=2) (7=1)

}

if `w'==67 {
gen refdate = mdy(04,18,1999)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==68 {
gen refdate = mdy(06,13,1999)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==69 {
gen refdate = mdy(03,12,2000)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}
}

if `w'==70 {
gen refdate = mdy(05,21,2000)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==71 {
gen refdate = mdy(09,24,2000)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}


}

if `w'==72 {
gen refdate = mdy(11,26,2000)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==73 {
gen refdate = mdy(03,04,2001)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}


}

if `w'==74 {
gen refdate = mdy(06,10,2001)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==75 {
gen refdate = mdy(12,02,2001)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==76 {
gen refdate = mdy(03,03,2002)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==77 {
gen refdate = mdy(06,02,2002)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (5=7) (7=4) (8=5) (9=6)

}

}

if `w'==78 {
gen refdate = mdy(09,22,2002)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==79 {
gen refdate = mdy(11,24,2002)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==80 {
gen refdate = mdy(02,09,2003)
format refdate %dM_d,_CY


foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

if `w'==81 {
gen refdate = mdy(05,18,2003)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

drop if `var'==.
}

}

if `w'==82 {
gen refdate = mdy(02,08,2004)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

}

gen date  = string(stdatum,"%06.0f")



if inrange(`w', 62,68){

replace date = substr(date,3,2) + substr(date,1,2)+ "19" +substr(date,5,2)

}

if inrange(`w', 69,82){

replace date = substr(date,3,2) + substr(date,1,2) + "20" + substr(date,5,2)

}

if `w'==62{
replace date = substr(date,3,2) + substr(date,1,2) + "1997"


}

if `w'==63 {

replace date = substr(date,3,2) + substr(date,1,2) + "1998"

}

if `w'==74{
replace date = substr(date,3,2) + substr(date,1,2) + "2001"


}

if `w'==75{

replace date = substr(date,3,2) + substr(date,1,2) + "2001"

}


gen intdate = daily(date, "MDY")
format intdate %dM_d,_CY


rename p02_new p02
label var p02 "Affinität zur Partei"

*missing intdate variables for waves 64, 66, 67, 68, 69, 70, 71, 72, 73, 76, 78

save $targetmac/vox`w'_clean.dta, replace

}

*-------------------------------------------------------------------------------

*WAVES 83 - 92

forvalues w=83(1)92 {

if inlist(`w',86) continue

use $targetmac/vox`w'.dta, clear

*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=11 6=5 8=10 9=7 10=8 11=21 12=2 13=1 14=14 15=15 16=16 17=17 18=18 19=19, gen(p02_new)


*recode s41 
recode s41 (6/7=6)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 13 "BDP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG", replace
label values p02_new p02_new
fre p02_new


rename plz qtplz

gen voxnr = `w'

if inlist(`w',84){
 gen gewteil =1

}

keep bildung s15 s18 s41 s11 s12 s61 s60 p04 p08 p01 p02_new a01 a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz voxnr gewteil stdatum

if `w'==83 {
gen refdate = mdy(05,16,2004)
format refdate %dM_d,_CY


}

if `w'==84 {
gen refdate = mdy(09,26,2004)
format refdate %dM_d,_CY



}

if `w'==85 {
gen refdate = mdy(11,28,2004)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)


}

if `w'==87 {
gen refdate = mdy(06,05,2005)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

}

if `w'==88 {
gen refdate = mdy(09,25,2005)
format refdate %dM_d,_CY
replace s41=6 if s41==.

}

if `w'==89 {
gen refdate = mdy(11,27,2005)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
}

if `w'==90 {
gen refdate = mdy(05,21,2006)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
}

if `w'==91 {
gen refdate = mdy(09,24,2006)
format refdate %dM_d,_CY

}

if `w'==92 {
gen refdate = mdy(11,26,2006)
format refdate %dM_d,_CY

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
}

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

gen date  = string(stdatum,"%06.0f")

replace date = substr(date,3,2) + substr(date,1,2)+ "20" +substr(date,5,2)

gen intdate = daily(date, "MDY")
format intdate %dM_d,_CY

rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox`w'_clean.dta, replace


}

*-------------------------------------------------------------------------------

*WAVES 93/94

forvalues w=93(1)94{

use $targetmac/vox`w'.dta, clear


*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=11 6=5 8=10 9=7 10=8 11=21 12=2 13=1 14=6 16=14 17=15 18=16 19=17 20=18 21=19, gen(p02_new)

*recode s41 
recode s41 (6/7=6)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG", replace
label values p02_new p02_new
fre p02_new

rename plz qtplz
rename date stdatum

gen voxnr = `w'


keep bildung s15 s18 s41 s11 s12  s61 s60 p04 p08 p01 a01 p02_new a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz voxnr nr gewteil stdatum

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

if `w'==93 {
gen refdate = mdy(03,11,2007)
format refdate %dM_d,_CY

}

if `w'==94 {
gen refdate = mdy(06,17,2007)
format refdate %dM_d,_CY

}

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}


rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox`w'_clean.dta, replace
}

*-------------------------------------------------------------------------------

*WAVES 95/96

forvalues w=95(1)96{


use $targetmac/vox`w'.dta, clear

 
*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=11 6=5 7=6 8=10 9=7 10=8 11=2 12=1 13=14 14=15 15=16 16=17 17=18 18=19, gen(p02_new)

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*recode s41 
recode s41 (6/7=6)

*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG", replace
label values p02_new p02_new
fre p02_new

rename plz qtplz
if `w' ==96{
}


gen voxnr = `w'
rename date stdatum

keep bildung s15 s18 s41 s11 s12  s61 s60 p04 p08 p01 p02_new a01 a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz  voxnr gewteil nr stdatum 

if `w'==95 {
gen refdate = mdy(02,24,2008)
format refdate %dM_d,_CY

}

if `w'==96 {
gen refdate = mdy(06,01,2008)
format refdate %dM_d,_CY

}


foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}
*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox`w'_clean.dta, replace


}

*-------------------------------------------------------------------------------

*WAVES 97-98

forvalues w=97(1)98{

use $targetmac/vox`w'.dta, clear


*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 6=5 7=6 8=10 9=7 10=8 11=2 12=1 13=13 14=14 15=15 16=16 17=17 18=18 19=19, gen(p02_new)

*recode s41 
recode s41 (6/7=6)

*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 13 "BDP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG", replace
label values p02_new p02_new
fre p02_new


rename plz qtplz
rename date stdatum

gen voxnr = `w'

keep bildung s15 s18 s41 s11 s12  s61 s60 p04 p08 p01 p02_new a01 a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz gewteil voxnr nr stdatum

if `w'==97 {
gen refdate = mdy(11,30,2008)
format refdate %dM_d,_CY

}

if `w'==98 {
gen refdate = mdy(02,08,2009)
format refdate %dM_d,_CY

}

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7)

}

*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox`w'_clean.dta, replace


}


*-------------------------------------------------------------------------------

*WAVES 99 - 105

forvalues w=99(1)105{

use $targetmac/vox`w'.dta, clear


*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 6=5 7=6 8=10 9=8 10=2 11=1 12=13 13=14 14=15 15=16 16=17 18=19, gen(p02_new)

*recode s41 
recode s41 (1=1) (2=2) (3=3) (4=4) (5/8 =5) (9/10=6)
*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA /AL/POP/sol" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 13 "BDP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG", replace
label values p02_new p02_new
fre p02_new


rename plz qtplz
rename date stdatum

if inlist(`w',99,100){

rename nummer nr

}

if inrange(`w',99,101){

gen gew1=.

}


if `w'==100 {

gen a91l=.

}

gen voxnr = `w'

keep bildung s15 s18 s41 s11 s12  s61 s60 p04 p08 p01 a01 p02_new a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz gewteil voxnr nr stdatum gew1



if `w'==99 {
gen refdate = mdy(05,17,2009)
format refdate %dM_d,_CY

}

if `w'==100 {
gen refdate = mdy(09,27,2009)
format refdate %dM_d,_CY

}


if `w'==101 {
gen refdate = mdy(11,29,2009)
format refdate %dM_d,_CY

}


if `w'==102 {
gen refdate = mdy(03,07,2010)
format refdate %dM_d,_CY

}


if `w'==103 {
gen refdate = mdy(09,26,2010)
format refdate %dM_d,_CY

}


if `w'==104 {
gen refdate = mdy(11,28,2010)
format refdate %dM_d,_CY

}


if `w'==105 {
gen refdate = mdy(02,13,2011)
format refdate %dM_d,_CY

}

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7) if `var' !=.

}

*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox`w'_clean.dta, replace

}


*-------------------------------------------------------------------------------

*Wave 106

use $targetmac/vox106.dta, clear

*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=5 6=6 7=10 8=8 9=2 10=1 11=13 12=26 13=14 14=15 15=27 16=17 17=18 18=19, gen(p02_new)
*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)
*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 13 "BDP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG" 26 "MCR" 27 "leere Liste", replace
label values p02_new p02_new
fre p02_new

*recode s41 
recode s41 (1=1) (2=2) (3=3) (4=4) (5/8 =5) (9/10=6)

rename plz qtplz
rename date stdatum

gen voxnr =106


*there is no var a91g
gen a91g=.


keep bildung s15 s18 s41 s11 s12 s61 s60 p04 p08 p01 a01 p02_new a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz gewteil voxnr nr gew1

gen refdate = mdy(03,11,2012)
format refdate %dM_d,_CY

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7) if `var' !=.

}
*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox106_clean.dta, replace

*-------------------------------------------------------------------------------

*Waves 107 - 121

forvalues w=107(1)121{ 

if inlist(`w',114) continue

use $targetmac/vox`w'.dta, clear

*unify p02's value labels for all waves:
recode p02 1=12 2=4 3=9 4=3 5=5 6=6 7=10 8=8 9=2 10=1 11=13 12=26 13=14 14=15 15=27 16=17 17=18 18=19, gen(p02_new)
*recode var p01
recode p01 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

*recode var p04
recode p04 (1=1) (2=2) (3=11) (4=12) (5=13) (6=3) (7=4) (8=5) (9=6) (10=7) (11=8) (12=9) (13=10)

label define p02_new 1 "SVP" 2 "SP" 3 "FDP" 4 "CVP" 5 "GP" 6 "GLP" 7 "LPS" 8 "PdA" 9 "EVP" 10 "Lega dei Ticinesi" 11 "EDU" 12 "CSP" 13 "BDP" 14 "eindeutig andere" 15 "mehrere Parteien gleichzeitig" 16 "keine Partei, bestimmte Person" 17 "keine Partei" 18 "kann sich nicht entscheiden" 19 "Antwortverweigerung" 20 "FPS" 21 "SD" 22 "LdU" 23 "FraP" 24 "GB" 25 "ADG" 26 "MCR" 27 "leere Liste", replace
label values p02_new p02_new
fre p02_new

*recode s41 
recode s41 (1=1) (2=2) (3=3) (4=4) (5/8 =5) (9/10=6)

rename plz qtplz
rename date stdatum

gen voxnr = `w'

keep bildung s15 s41 s18 s11 s12  s61 s60 p04 p08 p01 a01 p02_new a22 a91a a91c a91e a91f a91g a91h a91i a91j a91k a91l a91mg a91n e911 e912 s14a1 s14a1n s14a2 s14a3 s14a4 s14a5 s14a6 qtplz gewteil voxnr nr gew1

if inrange(`w', 107, 109){
*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

}

if `w'==107 {
gen refdate = mdy(06,17,2012)
format refdate %dM_d,_CY

}


if `w'==108 {
gen refdate = mdy(09,23,2012)
format refdate %dM_d,_CY

}

if `w'==109 {
gen refdate = mdy(11,25,2012)
format refdate %dM_d,_CY

}

if `w'==110 {
gen refdate = mdy(03,03,2013)
format refdate %dM_d,_CY

}

if inrange(`w', 111, 121){
*replace var s12 = its value labels
decode s12 ,gen(s12_clean)
destring s12_clean, replace
replace s12=s12_clean
drop s12_clean

}

if `w'==111 {
gen refdate = mdy(06,09,2013)
format refdate %dM_d,_CY

}

if `w'==112 {
gen refdate = mdy(09,22,2013)
format refdate %dM_d,_CY

}

if `w'==113 {
gen refdate = mdy(11,24,2013)
format refdate %dM_d,_CY

*recode var s61 

recode s61 (7=6)

foreach var in s14a2 s14a3 s14a4 s14a5 s14a6 s14a1n {

recode `var' (1=1) (2=2) (3=3) (4=3)

}

}

if `w'==114 {
gen refdate = mdy(02,09,2014)
format refdate %dM_d,_CY

}

if `w'==115 {
gen refdate = mdy(05,18,2014)
format refdate %dM_d,_CY

}

if `w'==116 {
gen refdate = mdy(09,28,2014)
format refdate %dM_d,_CY

}

if `w'==117 {
gen refdate = mdy(11,30,2014)
format refdate %dM_d,_CY

}

if `w'==118 {
gen refdate = mdy(03,08,2015)
format refdate %dM_d,_CY

}

if `w'==119 {
gen refdate = mdy(06,14,2015)
format refdate %dM_d,_CY

}

if `w'==120 {
gen refdate = mdy(02,28,2016)
format refdate %dM_d,_CY

}

if `w'==121 {
gen refdate = mdy(06,05,2016)
format refdate %dM_d,_CY

}

foreach var of global values {

recode `var' (1=1) (2=2) (3=3) (4=4) (5=5) (6=6) (7/8=7) if `var' !=.

}


rename p02_new p02
label var p02 "Affinität zur Partei"
save $targetmac/vox`w'_clean.dta, replace

}

*-------------------------------------------------------------------------------
